/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.insurance.cis.controllers;

import com.insurance.cis.daos.EmployeeDao;
import com.insurance.cis.models.Employee;
import com.insurance.cis.utils.MessageDialogUtils;
import com.insurance.cis.views.LoginJPanelView;

/**
 *
 * @author TruongLQ
 */
public class LoginController {
    
    final EmployeeDao employeeDao = new EmployeeDao();
    final LoginJPanelView loginJpnl;
    
    public LoginController(javax.swing.JPanel jPanel) {
        this.loginJpnl = (LoginJPanelView)jPanel;
    }
    
    public boolean checkEmployee(String username, String password) {
        Employee employee = employeeDao.getEmployee(username, password);
        if (employee !=null) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean isValidInputs() {
        if (loginJpnl.getTxtUsername().getText().trim().isEmpty()) {
            MessageDialogUtils.dialogError(loginJpnl, "User name must not be blank!");
            loginJpnl.getTxtUsername().requestFocus();
            return false;
        } 
        if (loginJpnl.getTxtPassword().getPassword().length ==0) {
            MessageDialogUtils.dialogError(loginJpnl, "Password must not be blank!");
            loginJpnl.getTxtPassword().requestFocus();
            return false;
        } 
        return true;
    }
    
    public void clearLoginJPanel() {
        loginJpnl.getTxtUsername().setText("");
        loginJpnl.getTxtPassword().setText("");
    }
}
